package org.csc.sss.ui.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Controller
public class MainController extends BaseController {

    @RequestMapping(value = "/")
    public void base(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        String basePath = getBasePath(request);
        try {
            response.sendRedirect(basePath + "/login");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    @RequestMapping(value =  "login")
    public String viewIndex(HttpServletRequest request, HttpServletResponse response,Model model) {
        log.info("跳转至-{}", "登录页面");
        return "login";
    }

    @RequestMapping(value = "/{path}")
    public String viewHTML(@PathVariable("path") String path) {
        log.info("访问-{}", path);
        return path;
    }

}
